import Vue from 'vue';
import axios from './router/axios';
import VueAxios from 'vue-axios';
import App from './App';
import router from './router/router';
import './permission'; // 权限
import './error'; // 日志
import './cache'; //页面缓存
import store from './store';
import { dragDialog, loadStyle } from './util/util';
import * as urls from '@/config/env';
import Element from 'element-ui';
import { iconfontUrl, iconfontVersion } from '@/config/env';
import i18n from './lang'; // Internationalization
import * as util from '@/util/index.js';
// 轮播图
import VueAwesomeSwiper from 'vue-awesome-swiper';
import Print from 'vue-print-nb';
import { statusText } from '@/components/common-modal-template/statusText.js';
import VxeUITable from 'vxe-table';
import 'vxe-table/lib/style.css';
// style
import './styles/common.scss';
import '@/assets/iconfont/iconfont.css';

import '@/plugins/directors.js'; // 自定义指令
import '@/plugins/globalComponent.js'; // 全局组件
import '@/plugins/tool.js'; // lodash,monent,website
// 轮播图样式
import 'swiper/css/swiper.css';
import { mounted } from 'vue2-ace-editor';

// 修改 el-dialog 默认点击遮照为不关闭
// Element.Dialog.props.closeOnClickModal.default = false

import html2pdf from 'html2pdf.js';
Vue.config.devtools = true;
Vue.prototype.$util = util;
Vue.prototype.$html2pdf = html2pdf;
Vue.prototype.$statusText = statusText;
// 1 重写Avue中crud中初始的option的方法
function init(type) {
  // 把这个拖拽属性 { dialogDrag: true } 合并到原option中
  this.tableOption = Object.assign(this.option, { dialogDrag: true, refreshBtn: false, columnBtn: false, searchShowBtn: false });
  this.getIsMobile();
  this.handleLocalDic();
  if (type !== false) this.handleLoadDic();
}

// 2 给全局element - dialog 组件加拖动
Vue.component('el-dialog', {
  extends: Element.Dialog,
  // 弹窗组件的逻辑
  mounted() {
    // 拖动函数
    dragDialog(this);
  }
});

AVUE.Crud.mixins[0].methods.init = init;
//全局修改默认配置(配置弹层点击模态层不可关闭)
Element.Dialog.props.closeOnClickModal.default = false;

// 加载Vue拓展
Vue.use(router);
Vue.use(VueAxios, axios);
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(Element.Dialog);
Vue.use(VueAwesomeSwiper);
Vue.use(window.AVUE, {
  size: 'small',
  tableSize: 'small',
  calcHeight: 65,
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(Print);
Vue.use(VxeUITable);
// 加载相关url地址
Object.keys(urls).forEach((key) => {
  Vue.prototype[key] = urls[key];
});

// 动态加载阿里云字体库
iconfontVersion.forEach((ele) => {
  loadStyle(iconfontUrl.replace('$key', ele));
});

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App)
}).$mount('#app');
